<div class="bg-dark-800 flex flex-col">
    {% if specter.info.get("initialblockdownload") == True %}
        <div class="flex flex-col p-4">
            <p id="progress-description">{{ _("Spectrum is syncing")}}<p>
            <div id="progress-bar-container" class="w-full bg-dark-700 rounded-lg">
                <div id="progress-bar" class="bg-dark-600 text-xs text-white text-center p-2 leading-none rounded-lg">Please wait a few minutes</div>
            </div>
        </div>
    {% endif %}
    {% if specter.chain %}
        <div class="m-3 mb-1">
            <table>
                <tr> <td>{{ _("Network") }}</td> <td class="text-right" id="node-info-specter-chain">{{specter.chain}}</td> </tr>
                <tr> <td>{{ _("Blocks count") }}</td> <td class="text-right">{{specter.info['blocks']}}</td> </tr>
                <tr> <td>{{ _("Host") }}</td> <td class="text-right" id="node-info-specter-chain">{{specter.node.host}}</td> </tr>
                <tr> <td>{{ _("Port") }}</td> <td class="text-right" id="node-info-specter-chain">{{specter.node.port}}</td> </tr>
                <tr> <td>{{ _("Tor") }}:</td> <td class="text-right" id="node-info-specter-chain">{{specter.node.uses_tor}}</td> </tr>
                <tr> <td>{{ _("SSL") }}</td> <td class="text-right" id="node-info-specter-chain">{{specter.node.ssl}}</td> </tr>
                <tr> <td>{{ _("Node uptime") }}</td> <td class="text-right">~ {{(specter.info['uptime'] / 60 // 60) | int }} {{ _("Hours") }}</td> </tr>
            </table>
        </div>

        <div class="px-3 pb-4 mt-2">
            {% if current_user.is_admin %}
                <div class="button mb-0">
                    <a id="active-node-settings-btn" href="{{ url_for('nodes_endpoint.node_settings', node_alias=specter.node.alias) }}">
                        <div class="flex items-center">
                            <svg class="w-6 h-6 mr-2" version="1.1" viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><!--Generated by IJSVG (https://github.com/iconjar/IJSVG)--><path d="M57.2844,34.2283l-3.9883,1.1395l3.17612e-08,-9.30007e-09c-0.360653,0.105603 -0.63181,0.404255 -0.7022,0.7734l2.47041e-07,-1.2278e-06c-0.177144,0.880411 -0.411338,1.74838 -0.7011,2.5984l-3.83885e-08,1.09619e-07c-0.124404,0.355235 -0.0388029,0.750235 0.2215,1.0221l2.8877,2.9844l-2.38852e-08,-2.46905e-08c0.310719,0.321195 0.370947,0.809422 0.1476,1.1965l-1.245,2.1564l1.45129e-08,-2.51485e-08c-0.223405,0.387125 -0.676446,0.579157 -1.11,0.4705l-4.05,-1.014l9.02177e-08,2.20782e-08c-0.364739,-0.0892593 -0.74875,0.0331841 -0.9945,0.3171l1.13486e-07,-1.29147e-07c-0.588383,0.669581 -1.2184,1.3014 -1.88629,1.89169l-5.24411e-08,4.53795e-08c-0.283821,0.245602 -0.406362,0.629363 -0.3174,0.994l1.01259,4.04671l3.48472e-08,1.38981e-07c0.108676,0.433433 -0.0831197,0.886398 -0.47,1.11l-2.1569,1.245l5.55443e-08,-3.20886e-08c-0.387013,0.223582 -0.875373,0.163379 -1.1965,-0.1475l-2.9992,-2.9018l2.9806e-09,2.85976e-09c-0.271609,-0.260598 -0.666603,-0.346484 -1.0219,-0.2222l-8.55655e-07,2.93141e-07c-0.844355,0.28927 -1.70648,0.523822 -2.581,0.7022l-1.77682e-08,3.4177e-09c-0.368526,0.0708855 -0.666568,0.341721 -0.7723,0.7018l-1.1433,4.0023l-9.60767e-10,3.35976e-09c-0.122881,0.42971 -0.515666,0.725951 -0.9626,0.726h-2.49l1.95129e-10,1.42109e-14c-0.446946,-1.56839e-05 -0.839748,-0.29627 -0.9626,-0.726l-1.1427,-4.0013l2.85457e-08,9.75162e-08c-0.105597,-0.360733 -0.404287,-0.631968 -0.7735,-0.7024l-2.04429e-06,-4.10898e-07c-0.876453,-0.176166 -1.74062,-0.408749 -2.58709,-0.696297l-6.37117e-08,-2.22625e-08c-0.355023,-0.124054 -0.749632,-0.0382612 -1.0211,0.222l-2.9929,2.8957l2.97278e-08,-2.87776e-08c-0.321159,0.310895 -0.809556,0.371098 -1.1966,0.1475l-2.1564,-1.2449l1.7065e-08,9.86637e-09c-0.386827,-0.223649 -0.578606,-0.676573 -0.47,-1.11l1.0147,-4.0524l1.33503e-08,-5.46011e-08c0.089308,-0.365259 -0.033593,-0.749759 -0.3182,-0.9955l4.36958e-07,3.82755e-07c-0.670548,-0.587369 -1.30328,-1.21656 -1.8944,-1.8838l9.23384e-09,1.06423e-08c-0.245655,-0.283127 -0.628953,-0.405207 -0.9931,-0.3163l-4.0444,1.0125l8.775e-08,-2.19707e-08c-0.433546,0.10855 -0.886524,-0.083455 -1.11,-0.4705l-1.24581,-2.1565l-1.00625e-08,-1.74301e-08c-0.223442,-0.387042 -0.16325,-0.875311 0.1475,-1.1965l2.8936,-2.99l3.5126e-08,-3.66489e-08c0.260682,-0.271984 0.346382,-0.667393 0.2217,-1.0229l-3.91852e-07,-1.14069e-06c-0.291297,-0.847972 -0.52739,-1.71391 -0.706798,-2.59239l1.30901e-09,6.829e-09c-0.0706561,-0.368607 -0.341534,-0.666738 -0.7017,-0.7723l-3.9891,-1.14l-1.47934e-08,-4.22479e-09c-0.429791,-0.122743 -0.726066,-0.515626 -0.7259,-0.9626v-2.49l-8.92497e-09,-2.4941e-05c-0.000154376,-0.446974 0.29613,-0.83985 0.725924,-0.962582l3.9883,-1.14l-2.31839e-08,6.79308e-09c0.360615,-0.105663 0.6317,-0.404358 0.702,-0.7735l-5.95606e-08,2.95638e-07c0.177365,-0.880379 0.411623,-1.74833 0.7013,-2.5984l5.45882e-09,-1.55782e-08c0.124479,-0.355233 0.0387827,-0.750276 -0.2217,-1.022l-2.88763,-2.9838l4.2055e-08,4.34676e-08c-0.31075,-0.321188 -0.370942,-0.809458 -0.1475,-1.1965l1.2449,-2.1565l-2.27863e-08,3.94183e-08c0.223626,-0.386854 0.67657,-0.578641 1.11,-0.47l4.0507,1.0141l1.71017e-08,4.18028e-09c0.364775,0.0891641 0.748769,-0.033351 0.9945,-0.3173l1.10855e-06,-1.26178e-06c0.58829,-0.669605 1.21824,-1.30143 1.8861,-1.8917l2.41601e-08,-2.08918e-08c0.283906,-0.245501 0.406435,-0.629306 0.3173,-0.9939l-1.0132,-4.0467l3.12657e-09,1.24656e-08c-0.108712,-0.433435 0.0830929,-0.886421 0.47,-1.11l2.1564,-1.245l-1.66979e-07,9.64141e-08c0.387051,-0.223485 0.875355,-0.163334 1.1966,0.1474l2.9993,2.902l-8.6721e-08,-8.31209e-08c0.27176,0.260478 0.666772,0.346275 1.0221,0.222l1.63393e-06,-5.59558e-07c0.844263,-0.289127 1.70624,-0.523677 2.5806,-0.7022l1.06423e-07,-2.04098e-08c0.368622,-0.0706944 0.666749,-0.341608 0.7723,-0.7018l1.1435,-4.0023l1.79162e-08,-6.2652e-08c0.122881,-0.42971 0.515666,-0.725951 0.9626,-0.726h2.49l-1.81415e-08,-3.36797e-12c0.446923,8.29866e-05 0.839689,0.29631 0.9626,0.726l1.1432,4.0014l3.05866e-09,1.04512e-08c0.105576,0.360746 0.404276,0.631989 0.7735,0.7024l9.2933e-07,1.86777e-07c0.876467,0.176152 1.74063,0.408769 2.58709,0.696397l9.1859e-08,3.2039e-08c0.355053,0.123837 0.749563,0.0380269 1.0211,-0.2221l2.9928,-2.8956l-6.39387e-08,6.18999e-08c0.321119,-0.310879 0.809458,-0.371121 1.1965,-0.1476l2.1564,1.245l6.29435e-08,3.63663e-08c0.386934,0.223555 0.578747,0.676562 0.47,1.11l-1.0145,4.0524l3.03479e-08,-1.24066e-07c-0.0893391,0.36523 0.03357,0.749717 0.3182,0.9954l-4.44877e-07,-3.89742e-07c0.670492,0.587396 1.30319,1.21658 1.8943,1.8838l5.44063e-08,6.27484e-08c0.245558,0.283209 0.628879,0.405308 0.993,0.3163l4.0446,-1.0124l1.88154e-08,-4.7207e-09c0.433438,-0.108747 0.886445,0.0830663 1.11,0.47l1.2448,2.1565l2.00317e-08,3.46804e-08c0.223538,0.387006 0.163382,0.875318 -0.1474,1.1965l-2.8935,2.9905l7.58168e-09,-7.91098e-09c-0.260643,0.271964 -0.346341,0.667323 -0.2217,1.0228l3.97908e-07,1.1585e-06c0.291265,0.848011 0.527325,1.71399 0.7067,2.5925l-4.45918e-08,-2.32536e-07c0.0706729,0.368543 0.3415,0.666623 0.7016,0.7722l3.9893,1.14l5.00553e-09,1.42976e-09c0.42979,0.122764 0.726085,0.515621 0.726,0.9626v2.49l1.04571e-09,-4.57524e-05c0,0.446542 -0.295802,0.839069 -0.72505,0.962137Zm-34.642,-14.4332l1.20408e-08,2.09575e-08c-0.139243,-0.242359 -0.448593,-0.325951 -0.690952,-0.186708c-0.0217675,0.0125061 -0.0425744,0.0266145 -0.0622482,0.0422084l-7.06444e-07,5.75336e-07c-6.83176,5.56387 -7.8596,15.6125 -2.29573,22.4443c0.685183,0.841323 1.45441,1.61055 2.29573,2.29573l-3.24386e-08,-2.57046e-08c0.219114,0.173628 0.537494,0.136754 0.711121,-0.0823603c0.0155403,-0.0196115 0.029605,-0.0403482 0.0420786,-0.0620397l5.76,-9.9758l-3.27835e-08,5.67828e-08c0.803848,-1.3923 0.803848,-3.1077 6.55671e-08,-4.5Zm9.3676,-3.7751l-3.97185e-08,-4.28564e-11c-1.93584,-0.00208884 -3.8559,0.348046 -5.6664,1.0333l1.59642e-08,-6.32588e-09c-0.258314,0.102358 -0.384741,0.39474 -0.282384,0.653053c0.00930422,0.0234805 0.0203634,0.046227 0.0330837,0.0680467l5.7712,9.9961l1.04316e-07,1.80681e-07c0.803845,1.3923 2.28941,2.24999 3.8971,2.25h11.5258l2.01323e-08,1.22746e-11c0.279566,0.000170446 0.506338,-0.226325 0.506509,-0.505891c1.51213e-05,-0.0248021 -0.0017926,-0.0495717 -0.00540855,-0.0741087l5.76739e-08,3.53837e-07c-1.26087,-7.73562 -7.94179,-13.4178 -15.7795,-13.4205Zm15.2779,18h-11.5248l1.72855e-07,-5.47118e-13c-1.60769,5.05322e-06 -3.09326,0.857699 -3.8971,2.25l-5.7712,9.996l-2.04905e-08,3.51481e-08c-0.139939,0.240042 -0.0587888,0.548078 0.181253,0.688016c0.0218196,0.0127203 0.0445662,0.0237795 0.0680467,0.0330837l9.02978e-07,3.41327e-07c8.2646,3.12404 17.4969,-1.04322 20.621,-9.30782c0.376648,-0.996419 0.652834,-2.02797 0.824446,-3.07928l2.5842e-09,-1.77608e-08c0.040261,-0.276708 -0.151417,-0.533662 -0.428125,-0.573923c-0.0241659,-0.00351614 -0.0485545,-0.00527928 -0.0729748,-0.00527562Z" fill="currentColor" fill-rule="evenodd"></path></svg>
                            {{ _("Configure connection") }}
                        </div>
                    </a>
                </div>
            {% endif %}
        </div>
    {% endif %}
</div>

<script>
    document.addEventListener("DOMContentLoaded", () => {
        {% if node.is_running and specter.node.rpc.getblockchaininfo().get("initialblockdownload") == True %}
            updateProgressBar()
        {% endif %}
    })

    const progressBar = document.getElementById('progress-bar')
    const progressBarContainer = document.getElementById('progress-bar-container')
    const progressDescription = document.getElementById('progress-description')

    async function updateProgressBar() {
		let url = `{{ url_for('nodes_endpoint.get_sync_progress') }}`;
		const response = await send_request(url, 'GET', "{{ csrf_token() }}");
        let syncProgress = response.syncProgress;
        if (syncProgress === 100) {
            progressBarContainer.classList.add('hidden') 
            progressDescription.innerText = "Spectrum is fully synced now."
        }
        else {
            progressBar.style.width = `${syncProgress}%`;
            progressBar.textContent = `${Math.round(syncProgress)}%`;
            setTimeout(updateProgressBar, 10000);
        } 
	}
</script>
